//
//  DKRepayChannelsView.m
//  DanKU
//
//  Created by EDY on 2023/11/10.
//

#import "DKRepayChannelsView.h"
#import "DKUILabel+CustomText.h"
#import "OrderTool.h"
#import "DKService.h"
#import "DKWebViewController.h"

@interface DKRepayChannelsView()<UICollectionViewDelegate,UICollectionViewDataSource>

@property(nonatomic,strong)UIView *dk_WarnView;
@property(nonatomic,strong)UIImageView *dk_WarnCellImg;
@property(nonatomic,strong)UILabel *dk_WarnCellcontentlab;

@property(nonatomic,strong)UIImageView *dk_CountBackView;
@property(nonatomic,strong)UILabel *dk_ExtensionFee;
@property(nonatomic,strong)UILabel *dk_Countlabel;
@property(nonatomic,strong)UILabel *dk_DueDate;
@property(nonatomic,strong)UILabel *dk_TimeDate;

@property(nonatomic,strong)UIButton *dk_payButton;

@property(nonatomic,strong)UILabel *dk_CoopChannel;
//@property(nonatomic,strong)UIButton *dk_SFPay;
//@property(nonatomic,strong)UIButton *dk_Zeropay;
//@property(nonatomic,strong)UIButton *dk_Tpay;

@property(nonatomic,strong)UIView *dk_OrderCellView;
@property(nonatomic,strong)UIImageView *dk_OrderIcon_BackImg;
@property(nonatomic,strong)UIImageView *dk_OrderIconImg;
@property(nonatomic,strong)UILabel *dk_OrderTitlelab;
@property(nonatomic,strong)UILabel *dk_OrderLine;
@property(nonatomic,strong)UILabel *dk_OrderCountlab;


@property(nonatomic,strong)NSMutableArray  *imageList;
@property(nonatomic,strong)UICollectionView *collectionView;

@property (nonatomic,strong)DKRepaymentCodeListModel *RepaymentCode;


@end

@implementation DKRepayChannelsView

-(void)setDataSoure:(DKOrderDetailModel *)dataSoure{// 正常还款  展期还款
    _dataSoure = dataSoure;
        self.dk_Countlabel.text = [NSString stringWithFormat:@"-%@",[OrderTool formatAmountForIndia:dataSoure.repayAmount]];
//    }else{
//        self.dk_Countlabel.text = [OrderTool formatAmountForIndia:dataSoure.repayAmount];
//    }
    
    self.dk_OrderTitlelab.text = dataSoure.productName;
    
    DKOrderDetailPairsModel  *model = [dataSoure.pairs firstObject];
    self.dk_TimeDate.text = model.value;
}

-(void)setExtenceSoure:(DKDelayFlexibleModel *)extenceSoure{// 展期还款
    _extenceSoure = extenceSoure;
        self.dk_Countlabel.text = [NSString stringWithFormat:@"%@",[OrderTool formatAmountForIndia:extenceSoure.amount]];
//    }else{
//        self.dk_Countlabel.text = [OrderTool formatAmountForIndia:extenceSoure.amount];
//    }
    
    NSString *formattedDateString = [OrderTool stringFromTimestampString:extenceSoure.delayExpiryTime];
    NSString  *changeString = [OrderTool convertDate:formattedDateString fromFormat:@"yyyy-MM-dd HH:mm:ss" toFormat:@"dd-MM-yyyy"];
    self.dk_TimeDate.text = changeString;
}

-(void)setImageListSoure:(DKBankimagesModel *)imageListSoure{
    if (imageListSoure) {
        [self.imageList addObjectsFromArray:imageListSoure.data];
        [self.collectionView reloadData];
    }
}

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame: frame]) {
        self.backgroundColor =  DK_Hex(@"#FAFAFA");
        [self creatUI];
        self.imageList = [NSMutableArray array];
        
        
    }
    return self;
}

-(void)setDkRepayChannelsType:(DKRepayChannelsType)dkRepayChannelsType{
    _dkRepayChannelsType = dkRepayChannelsType;
    if (dkRepayChannelsType == Pay) {// 展期还款
        [self.dk_payButton setTitle:@"Pay" forState:UIControlStateNormal];
    }else{// 结清还款
        [self.dk_payButton setTitle:@"Repay" forState:UIControlStateNormal];
        self.dk_ExtensionFee.text = @"Bill amount";
        self.dk_TimeDate.hidden = YES;
        self.dk_DueDate.hidden = YES;
        
    }
}

#pragma mark 点击事件
-(void)Submit:(UIButton *)sender{
    sender.enabled = NO;
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        sender.enabled = YES;
    });
    // 还款详情 获取还款 URL
    [SVProgressHUD show];
    [DKPublicHttp apiGetOrderRepayDetailAPI:@{@"orderNo":[NSString stringWithFormat:@"%@",self.dataSoure.orderNo],@"delayTerm":@"0",@"requestType":@"0"} complete:^(DKRepaymentDetailModel * _Nonnull orderlist) {
        if (orderlist.repaymentCodeList.count>0) {
            self.RepaymentCode = [orderlist.repaymentCodeList firstObject];
            DKWebViewController *vc = [[DKWebViewController alloc]initWithUrl:self.RepaymentCode.paymentCode withIsNavBar:YES];
            if(![[self viewController] isKindOfClass:[DKWebViewController class]]){
                if (self.dkRepayChannelsType == Pay) {// 展期还款  数据上报
                    [self reportRepayment:@"Delay" URL:self.RepaymentCode.paymentCode];
                }else{// 结清还款
                    [self reportRepayment:@"Total" URL:self.RepaymentCode.paymentCode];
                }
                [[self viewController].navigationController pushViewController:vc animated:YES];
            }
        }
        [SVProgressHUD dismiss];
    }];
    
    if (self.dkRepayChannelsType == Pay) {// 展期还款
        [self reportClick:@"DelayRepayment"];
    }else{// 结清还款
        [self reportClick:@"TotalRepayment"];
    }
}


-(void)reportRepayment:(NSString*)string  URL:(NSString*)url{
    [DKPublicHttp apiUserBrhavRecordForAPI:@{@"type":string,@"url":[NSString stringWithFormat:@"%@",url]} withPageName:@"Repayment" withAction:@"Enter" complete:^{
            
    } fail:^{
            
    }];
}


-(void)reportClick:(NSString*)string{
    [DKPublicHttp apiUserBrhavRecordForAPI:@{@"loanOrderId":[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",self.dataSoure.orderNo]]} withPageName:string withAction:@"Click" complete:^{
            
    } fail:^{
            
    }];
}


-(void)creatUI{
    [self addSubview:self.dk_WarnView];
    [self addSubview:self.dk_WarnCellImg];
    [self addSubview:self.dk_WarnCellcontentlab];
    [self.dk_WarnView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self).offset(10);
        make.height.mas_equalTo(80);
    }];
    
    [self.dk_WarnCellImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_WarnView).offset(10);
        make.top.equalTo(self.dk_WarnView).offset(15);
        make.height.mas_equalTo(12);
        make.width.mas_equalTo(14);
    }];
    
    [self.dk_WarnCellcontentlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.dk_WarnView).offset(10);
        make.left.equalTo(self.dk_WarnCellImg.mas_right).offset(8);
        make.right.equalTo(self.dk_WarnView).offset(-10);
        make.bottom.equalTo(self.dk_WarnView).offset(-10);
        
    }];
    
    
    [self addSubview:self.dk_CountBackView];
    [self.dk_CountBackView addSubview:self.dk_ExtensionFee];
    [self.dk_CountBackView addSubview:self.dk_Countlabel];
    [self.dk_CountBackView addSubview:self.dk_DueDate];
    [self.dk_CountBackView addSubview:self.dk_TimeDate];
    
    [self.dk_CountBackView mas_makeConstraints:^(MASConstraintMaker *make){
        make.left.right.equalTo(self.dk_WarnView);
        make.top.equalTo(self.dk_WarnView.mas_bottom).offset(15);
        make.height.mas_equalTo(150);
    }];
    
    [self.dk_ExtensionFee mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.dk_CountBackView);
        make.top.equalTo(self.dk_CountBackView).offset(15);
        make.height.mas_equalTo(30);
    }];
    
    [self.dk_Countlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.dk_CountBackView);
        make.top.equalTo(self.dk_ExtensionFee.mas_bottom);
        make.height.mas_equalTo(45);
    }];
    
    [self.dk_DueDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_CountBackView).offset(10);
        make.width.mas_equalTo(DK_SCREEN_W/3);
        make.bottom.equalTo(self.dk_CountBackView).offset(-10);
        make.height.equalTo(self.dk_ExtensionFee);
    }];
    
    [self.dk_TimeDate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.bottom.equalTo(self.dk_DueDate);
        make.right.equalTo(self.dk_CountBackView).offset(-10);
    }];
    
    
    [self addSubview:self.dk_payButton];
    [self.dk_payButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(DK_IsWidthScale(60)));
        make.right.equalTo(@(-DK_IsWidthScale(60)));
        make.top.equalTo(self.dk_CountBackView.mas_bottom).offset(DK_IsWidthScale(15));
        make.height.equalTo(@(DK_IsWidthScale(50)));
    }];
    
    [self addSubview:self.dk_CoopChannel];
//    [self addSubview:self.dk_SFPay];
//    [self addSubview:self.dk_Zeropay];
//    [self addSubview:self.dk_Tpay];
    
    [self.dk_CoopChannel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.dk_CountBackView);
        make.height.equalTo(self.dk_ExtensionFee);
        make.top.equalTo(self.dk_payButton.mas_bottom).offset(15);
    }];
    
    [self CreatCollectionView];
    
//    [self.dk_SFPay mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.dk_CoopChannel);
//        make.top.equalTo(self.dk_CoopChannel.mas_bottom).offset(10);
//        make.width.mas_equalTo((DK_SCREEN_W-60)/3);
//        make.height.mas_equalTo((DK_SCREEN_W-60)/6);
//    }];
//
//    [self.dk_Zeropay mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.height.top.equalTo(self.dk_SFPay);
//        make.left.equalTo(self.dk_SFPay.mas_right).offset(15);
//    }];
//
//    [self.dk_Tpay mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.width.height.top.equalTo(self.dk_SFPay);
//        make.left.equalTo(self.dk_Zeropay.mas_right).offset(15);
//    }];
    
    [self addSubview:self.dk_OrderCellView];
    [self.dk_OrderCellView addSubview:self.dk_OrderIcon_BackImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderIconImg];
    [self.dk_OrderCellView addSubview:self.dk_OrderTitlelab];
    [self.dk_OrderCellView addSubview:self.dk_OrderLine];
    [self.dk_OrderCellView addSubview:self.dk_OrderCountlab];
    
    [self.dk_OrderCellView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.equalTo(self.collectionView.mas_bottom).offset(10);
        make.bottom.equalTo(self);
    }];
    
    [self.dk_OrderIcon_BackImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.width.height.mas_equalTo(38);
        make.top.equalTo(self.dk_OrderCellView).offset(7);
    }];
    
    [self.dk_OrderIconImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(22);
        make.height.mas_equalTo(26);
        make.center.equalTo(self.dk_OrderIcon_BackImg);
    }];
    
    [self.dk_OrderTitlelab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg.mas_right).offset(10);
        make.width.mas_equalTo(DK_SCREEN_W/4);
        make.height.mas_equalTo(30);
        make.top.equalTo(self.dk_OrderCellView).offset(10);
    }];
    
    [self.dk_OrderLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderCellView).offset(15);
        make.right.equalTo(self.dk_OrderCellView).offset(-15);
        make.height.mas_equalTo(0.5);
        make.top.equalTo(self.dk_OrderIcon_BackImg.mas_bottom).offset(5);
    }];
    
    [self.dk_OrderCountlab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.dk_OrderIcon_BackImg);
        make.height.equalTo(self.dk_OrderTitlelab);
        make.width.mas_equalTo(DK_SCREEN_W/2);
        make.top.equalTo(self.dk_OrderLine.mas_bottom).offset(10);
    }];
}

-(UIView*)dk_WarnView{
    if (!_dk_WarnView) {
        _dk_WarnView = [[UIView alloc]init];
        _dk_WarnView.backgroundColor =  DK_HexA(@"#FF0000", 0.05);
        _dk_WarnView.layer.cornerRadius = 10;
    }
    return _dk_WarnView;
}

- (UIImageView*)dk_WarnCellImg{
    if (!_dk_WarnCellImg) {
        _dk_WarnCellImg = [[UIImageView alloc] init];
        _dk_WarnCellImg.image =  DK_GetImage(@"dk_warning_red");
    }
    return _dk_WarnCellImg;
}


- (UILabel *)dk_WarnCellcontentlab {
    if (!_dk_WarnCellcontentlab) {
        _dk_WarnCellcontentlab = [[TTTAttributedLabel alloc] initWithFrame:CGRectZero];
        _dk_WarnCellcontentlab.textColor = DK_Hex(@"#333333");
        _dk_WarnCellcontentlab.font = [UIFont systemFontOfSize:12];
        _dk_WarnCellcontentlab.numberOfLines = 0;
//        _dk_WarnCellcontentlab.text = @"1.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n2.After the transfer, please make sure to return to the app and paste Ref/UTR";
//        [_dk_WarnCellcontentlab addColoredText:@"latest UPI" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
//        [_dk_WarnCellcontentlab addColoredText:@"paste Ref/UTR" withColor:DK_Hex(@"#ED4342") andFont:[UIFont systemFontOfSize:12]];
        
        NSString *loanHead = @"1.UPI will expire, which may lead to repayment failure. Please use the latest UPI for repayment\n2.After the transfer, please make sure to return to the app and paste Ref/UTR";
        NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:loanHead];
        [attStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:12] range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#333333") range:NSMakeRange(0,attStr.length)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(71,10)];
        [attStr addAttribute:NSForegroundColorAttributeName value:DK_Hex(@"#ED4342") range:NSMakeRange(loanHead.length-7,7)];
        _dk_WarnCellcontentlab.attributedText = attStr;
    }
    return _dk_WarnCellcontentlab;
}

-(UIImageView*)dk_CountBackView{
    if (!_dk_CountBackView) {
        _dk_CountBackView = [[UIImageView alloc]init];
        _dk_CountBackView.layer.cornerRadius = 10;
        _dk_CountBackView.image = [UIImage imageNamed:@"bj_repayment"];
    }
    return _dk_CountBackView;
}

- (UILabel *)dk_ExtensionFee {
    if (!_dk_ExtensionFee) {
        _dk_ExtensionFee = [[UILabel alloc] init];
        _dk_ExtensionFee.textColor = DK_Hex(@"#333333");
        _dk_ExtensionFee.font = [UIFont systemFontOfSize:14];
        _dk_ExtensionFee.text = @"Extension fee";
        _dk_ExtensionFee.textAlignment = 1;
    }
    return _dk_ExtensionFee;
}


- (UILabel *)dk_Countlabel {
    if (!_dk_Countlabel) {
        _dk_Countlabel = [[UILabel alloc] init];
        _dk_Countlabel.textColor = DK_Hex(@"#333333");
        _dk_Countlabel.font = [UIFont boldSystemFontOfSize:24];
        _dk_Countlabel.text = @"₹ 40,000";
        _dk_Countlabel.textAlignment = 1;
    }
    return _dk_Countlabel;
}

- (UILabel *)dk_DueDate {
    if (!_dk_DueDate) {
        _dk_DueDate = [[UILabel alloc] init];
        _dk_DueDate.textColor = DK_Hex(@"#333333");
        _dk_DueDate.font = [UIFont systemFontOfSize:14];
        _dk_DueDate.text = @"New due date";
    }
    return _dk_DueDate;
}

- (UILabel *)dk_TimeDate {
    if (!_dk_TimeDate) {
        _dk_TimeDate = [[UILabel alloc] init];
        _dk_TimeDate.textColor = DK_Hex(@"#333333");
        _dk_TimeDate.font = [UIFont systemFontOfSize:14];
        _dk_TimeDate.text = @"25-03-2022";
        _dk_TimeDate.textAlignment = 2;
    }
    return _dk_TimeDate;
}

-(UIButton*)dk_payButton{
    if (!_dk_payButton) {
        _dk_payButton = [[UIButton alloc]init];
        [_dk_payButton addTarget:self action:@selector(Submit:) forControlEvents:UIControlEventTouchUpInside];
        [_dk_payButton setTitle:@"Pay" forState:UIControlStateNormal];
        [_dk_payButton setTitleColor:DK_Hex(@"#FFFFFF") forState:UIControlStateNormal];
        _dk_payButton.titleLabel.font = DK_FONT_Semibold(14);
        [_dk_payButton setBackgroundColor:DK_Hex(@"#4566FF")];
        _dk_payButton.layer.cornerRadius = DK_IsWidthScale(20);
    }
    return _dk_payButton;
}

- (UILabel *)dk_CoopChannel {
    if (!_dk_CoopChannel) {
        _dk_CoopChannel = [[UILabel alloc] init];
        _dk_CoopChannel.textColor = DK_Hex(@"#333333");
        _dk_CoopChannel.font = [UIFont systemFontOfSize:14];
        _dk_CoopChannel.text = @"Cooperative payment channels:";
    }
    return _dk_CoopChannel;
}

//-(UIButton*)dk_SFPay{
//    if (!_dk_SFPay) {
//        _dk_SFPay = [[UIButton alloc] init];
//        [_dk_SFPay setBackgroundColor:[UIColor clearColor]];
//        [_dk_SFPay setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
//        [_dk_SFPay addTarget:self action:@selector(RepayAction) forControlEvents:UIControlEventTouchUpInside];
//        //        _dk_SFPay.backgroundColor = [UIColor redColor];
//    }
//    return _dk_SFPay;
//}
//
//
//
//-(UIButton*)dk_Zeropay{
//    if (!_dk_Zeropay) {
//        _dk_Zeropay = [[UIButton alloc] init];
//        [_dk_Zeropay setBackgroundColor:[UIColor clearColor]];
//        [_dk_Zeropay setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
//        [_dk_Zeropay addTarget:self action:@selector(RepayAction) forControlEvents:UIControlEventTouchUpInside];
//        //        _dk_Zeropay.backgroundColor = [UIColor redColor];
//    }
//    return _dk_Zeropay;
//}
//
//-(UIButton*)dk_Tpay{
//    if (!_dk_Tpay) {
//        _dk_Tpay = [[UIButton alloc] init];
//        [_dk_Tpay setBackgroundColor:[UIColor clearColor]];
//        [_dk_Tpay setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
//        [_dk_Tpay addTarget:self action:@selector(RepayAction) forControlEvents:UIControlEventTouchUpInside];
//        //        _dk_Tpay.backgroundColor = [UIColor redColor];
//    }
//    return _dk_Tpay;
//}

-(UIView*)dk_OrderCellView{
    if (!_dk_OrderCellView) {
        _dk_OrderCellView = [[UIView alloc]init];
        _dk_OrderCellView.backgroundColor = DK_Hex(@"#FFFFFF");
        _dk_OrderCellView.layer.cornerRadius = 10;
    }
    return _dk_OrderCellView;
}

- (UIImageView*)dk_OrderIcon_BackImg{
    if (!_dk_OrderIcon_BackImg) {
        _dk_OrderIcon_BackImg = [[UIImageView alloc] init];
        _dk_OrderIcon_BackImg.image =  DK_GetImage(@"dk_order_list_back_img");
    }
    return _dk_OrderIcon_BackImg;
}

- (UIImageView*)dk_OrderIconImg{
    if (!_dk_OrderIconImg) {
        _dk_OrderIconImg = [[UIImageView alloc] init];
        _dk_OrderIconImg.image =  DK_GetImage(@"dk_order_list_img");
    }
    return _dk_OrderIconImg;
}

- (UILabel *)dk_OrderTitlelab {
    if (!_dk_OrderTitlelab) {
        _dk_OrderTitlelab = [[UILabel alloc] init];
        _dk_OrderTitlelab.textColor = DK_Hex(@"#333333");
        _dk_OrderTitlelab.font = [UIFont boldSystemFontOfSize:15];
        _dk_OrderTitlelab.text = @"Go 002";
    }
    return _dk_OrderTitlelab;
}

- (UILabel *)dk_OrderLine {
    if (!_dk_OrderLine) {
        _dk_OrderLine = [[UILabel alloc] init];
        _dk_OrderLine.backgroundColor = DK_Hex(@"#E0E0E0");
    }
    return _dk_OrderLine;
}

- (UILabel *)dk_OrderCountlab {
    if (!_dk_OrderCountlab) {
        _dk_OrderCountlab = [[UILabel alloc] init];
        _dk_OrderCountlab.textColor = DK_Hex(@"#333333");
        _dk_OrderCountlab.font = [UIFont boldSystemFontOfSize:15];
        _dk_OrderCountlab.text = @"Extension details:";
    }
    return _dk_OrderCountlab;
}


-(void)CreatCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    CGFloat itemW = (DK_SCREEN_W-60) /3 ;
    layout.itemSize = CGSizeMake(itemW, itemW);
    layout.sectionInset = UIEdgeInsetsMake(0, 20 ,0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
    self.collectionView.backgroundColor = DK_Hex(@"#FAFAFA");
    self.collectionView.showsHorizontalScrollIndicator = NO;
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    [self.collectionView registerClass:[DKBankUICollectionViewCell class] forCellWithReuseIdentifier:@"DKBankUICollectionViewCell"];
    [self addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.dk_CoopChannel.mas_bottom).offset(10);
        make.height.mas_equalTo((DK_SCREEN_W-60)/6);
    }];
}

#pragma mark -collectionview 数据源方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
 }

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.imageList.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    DKBankUICollectionViewCell *cell =  [collectionView dequeueReusableCellWithReuseIdentifier:@"DKBankUICollectionViewCell" forIndexPath:indexPath];
    cell.imageData = self.imageList[indexPath.row];
    return cell;
 }


-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    
}


//获取View所在的Viewcontroller方法
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}


@end



@interface DKBankUICollectionViewCell()

@property(nonatomic,strong)UIImageView *bankImg;

@end



@implementation DKBankUICollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = DK_Hex(@"#FFFFFF");
        self.layer.cornerRadius = 15;
        [self setuplUI];
    }
    return self;
}

-(void)setImageData:(DKBankimagesModelList *)imageData{
    NSLog(@"银行图片路径---%@",[NSString stringWithFormat:@"%@images/repayment/%@",DK_ServiceApiUrl,imageData.image]);
    [self.bankImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/images/repayment/%@",DK_ServiceApiUrl,imageData.image]]];
}

-(void)setuplUI{
    [self.contentView addSubview:self.bankImg];
    [self.bankImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
}

-(UIImageView*)bankImg{
    if (!_bankImg) {
        _bankImg = [[UIImageView alloc]init];
    }
    return _bankImg;
}


@end
